Skip to content

Feature/psf convolution refactor#282

Merged
Jammy2211 merged 6 commits intomainfrom
feature/psf_convolution_refactor
Feb 23, 2026
Merged

Feature/psf convolution refactor#282
Jammy2211 merged 6 commits intomainfrom
feature/psf_convolution_refactor

Conversation

@Jammy2211
Copy link
Copy Markdown
Collaborator

This pull request refactors the codebase to replace the use of Kernel2D as the point spread function (PSF) with a new Convolver class throughout the autogalaxy package. The changes update function signatures, internal logic, and tests to consistently use Convolver, and adjust all places where the PSF's shape or values are accessed to reference the underlying kernel within Convolver. This improves clarity and modularity in PSF handling.

Core refactor: PSF representation

  • Replaced all references to Kernel2D as the PSF with Convolver, including function arguments, return types, and internal logic across the codebase. [1] [2] [3] [4] [5] [6] [7] [8] [9]
  • Updated PSF shape and value accesses to reference psf.kernel.shape_native and psf.kernel.native, ensuring correct usage with the new Convolver structure. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]

Imaging and simulation logic

  • Modified imaging dataset loading and simulation to instantiate Convolver from kernel arrays, and updated relevant methods to accept and handle Convolver instances. [1] [2]
  • Adjusted simulator and plotting interfaces to use Convolver for PSF operations, including convolution and plotting. [1] [2] [3]

Test suite updates

Cleanup and consistency

  • Removed the unused import of Kernel2D from autogalaxy/__init__.py.
  • Ensured all convolution-related logic and PSF handling is centralized through the Convolver abstraction for improved maintainability. [1] [2]

These changes collectively modernize the PSF handling in the codebase, making it more robust and easier to extend in the future.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request refactors PSF handling across autogalaxy to use Convolver instead of Kernel2D, updating call sites, type hints, FITS IO, plotting, and tests to consistently reference the underlying kernel via psf.kernel.

Changes:

  • Replaced PSF types and construction from Kernel2D to Convolver across core code paths and tests.
  • Updated PSF shape/value access patterns to use psf.kernel.shape_native / psf.kernel.native(_for_fits).
  • Adjusted imaging simulation and aggregator FITS loading to build Convolver from stored kernel arrays.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
test_autogalaxy/profiles/light/test_snr.py Updates SNR test PSF creation to Convolver.from_gaussian.
test_autogalaxy/operate/test_image.py Refactors PSF setup to Convolver(kernel=...) and updates kernel shape access.
test_autogalaxy/imaging/test_simulator.py Updates simulator tests to compare PSF kernels and construct Convolver PSFs.
test_autogalaxy/imaging/test_simulate_and_fit_imaging.py Switches simulated PSF creation to Convolver.from_gaussian.
autogalaxy/profiles/light/snr/abstract.py Updates psf type hint to Optional[aa.Convolver] and uses convolution via Convolver.
autogalaxy/profiles/light/linear/abstract.py Updates linear objective function list to accept Optional[aa.Convolver] PSF.
autogalaxy/operate/image.py Updates image blurring APIs to accept aa.Convolver and uses psf.kernel.shape_native for padding.
autogalaxy/imaging/simulator.py Uses self.psf.kernel.shape_native when padding/trimming around convolution.
autogalaxy/imaging/model/plotter_interface.py Writes PSF to FITS using dataset.psf.kernel.native_for_fits.
autogalaxy/galaxy/to_inversion.py Updates inversion interface PSF type hint to Optional[aa.Convolver].
autogalaxy/galaxy/galaxy.py Updates galaxy SNR helper signature to accept Optional[aa.Convolver].
autogalaxy/aggregator/imaging/imaging.py Loads PSF kernel as Array2D and wraps it in aa.Convolver.
autogalaxy/init.py Re-exports Convolver and removes the Kernel2D re-export.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

from autoarray.structures.grids.uniform_2d import Grid2D # noqa
from autoarray.structures.grids.irregular_2d import Grid2DIrregular # noqa
from autoarray.operators.over_sampling.over_sampler import OverSampler # noqa
from autoarray.operators.convolver import Convolver
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Convolver is imported for public re-export like the other autoarray symbols, but it’s missing the # noqa marker. Without it, linting (unused import) may fail; align with the surrounding imports by adding # noqa (or otherwise ensuring it’s referenced in this module).

Suggested change
from autoarray.operators.convolver import Convolver
from autoarray.operators.convolver import Convolver # noqa

Copilot uses AI. Check for mistakes.
Comment on lines 45 to 51
def blurred_image_2d_from(
self,
grid: aa.Grid2D,
blurring_grid: aa.Grid2D,
psf: aa.Kernel2D = None,
psf: aa.Convolver = None,
xp=np,
) -> aa.Array2D:
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

psf defaults to None but is passed unconditionally into _blurred_image_2d_from, which calls psf.convolved_image_from(...). Either make psf required (remove the = None default / update call sites) or change the annotation to Optional[aa.Convolver] and add a no-PSF path (e.g., return the unblurred image).

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@Jammy2211 Jammy2211 merged commit f4b91fb into main Feb 23, 2026
8 checks passed
@Jammy2211 Jammy2211 deleted the feature/psf_convolution_refactor branch April 2, 2026 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants